
import {
  testKey
} from 'utils/switch.js'
import * as API from './api/loginApi';

App({
  onLaunch: function () {
    let token = wx.getStorageSync('token');
    let phone = wx.getStorageSync('phone');
    if (!token || !phone) {
      this.globalData.userInfo.phone = null
      this.globalData.userInfo.avatarPath = null
      this.globalData.userInfo.hasLogin = false
      this.globalData.userInfo.authentication = false
    } else {
      wx.showLoading({
        title: '正在加载数据'
      })
      API.getUserInfo().then(res => {
        wx.hideLoading()
        this.globalData.userInfo.phone = res.data && res.data.user.user.phone
        this.globalData.userInfo.id = res.data && res.data.user.user.id
        // this.globalData.userInfo.avatarPath = res.data && res.data.user.user.avatarPath
        this.globalData.userInfo.hasLogin = !!token
        this.globalData.userInfo.authentication = res.data && res.data.authentication
      }, err => {
        wx.hideLoading();
      })
    }
  },
  
  onShow: function (options) {
    
  },
  globalData: {
    userInfo: {
      openid: null,
      phone: null,
      id: null,
      // avatarPath: '',
      hasLogin: false,
      authentication: false
    }
  },
  onHide: function () {
  }
});
